﻿using System;
using Glue;
using Glue.Internals.Verification;
using Xunit;

namespace GlueTests.MapperVerificationTests
{
    public class When_mapping_flattened_relation
    {
       private readonly MapperVerification<DomainPerson, GuiPerson> verification;

        public class DomainPerson
        {
            public String Name { get; set; }
            public DomainAddress Address { get; set; }
        }

        public class DomainAddress
        {
            public String City { get; set; }
        }

        public class GuiPerson
        {
            public String Name { get; set; }
            public String City { get; set; }
        }

        public When_mapping_flattened_relation()
        {
            var addressMapping = new Mapping<DomainAddress, GuiPerson>();
            addressMapping.AutoRelateEqualNames();
            var mapping = new Mapping<DomainPerson, GuiPerson>();
            mapping.AutoRelateEqualNames();
            mapping.Flatten(domain=>domain.Address,addressMapping);
            verification = new MapperVerification<DomainPerson, GuiPerson>(mapping);
        }

        [Fact]
        public void Should_map_correctly_against_flattened_relation()
        {
            verification.AssertMapsCorrectlyTowards(new GuiPerson());
        }

        [Fact]
        public void Should_map_correctly_against_nested_relation()
        {
            verification.AssertMapsCorrectlyTowards(new DomainPerson{Address = new DomainAddress()});
        }
    }
}
